#include "front/text_normalize.h"

using namespace std;
using namespace ppspeech;

const wregex mcWregexScientificNotation(L"(\\+|-)?(\\d+)(\\.\\d+)?(E)(\\+|-)?(\\d+)");

void TextNormalizer::TnReScientificNotation(wstring* fpInWsentence, const LanguageEnum fcInLanguage)
{
	wsmatch tWsmatch;

	while(regex_search(*fpInWsentence, tWsmatch, mcWregexScientificNotation))
	{
		string tInSentence = wstring2utf8string(*fpInWsentence);
		string tStrMatch = wstring2utf8string(tWsmatch[0]);	//匹配到科学计数法的字符串

		vector<string> tVecItems = StrSplit(tStrMatch, "E");
		if(tVecItems.size() != 2) {
			return;
		}

		string tStrReplace = "";

		if(fcInLanguage == LANG_EN) {
			tStrReplace += " ";
			tStrReplace += ReplaceMethod(vector<string>{tVecItems[0]}, RME_en_negative_decimal);
			tStrReplace += " multipled by ten to the power of ";
			tStrReplace += ReplaceMethod(vector<string>{tVecItems[1]}, RME_en_negative_decimal);
			tStrReplace += " ";
		}
		else {
			tStrReplace += ReplaceMethod(vector<string>{tVecItems[0]}, RME_zh_negative_decimal);
			tStrReplace += "乘十的";
			tStrReplace += ReplaceMethod(vector<string>{tVecItems[1]}, RME_zh_negative_decimal);
			tStrReplace += "次幂";
		}

		WstrReplacePosition(fpInWsentence, tWsmatch.position(0), tWsmatch.length(0), utf8string2wstring(tStrReplace) );
	}
}
